import pymysql
# 建表

try:
    con = pymysql.connect(host="localhost",user="root",password="rootroot",db="blog")
    print(con)
    cursor = con.cursor()
    # 表如果存在就先删除
    cursor.execute('drop table if EXISTS student')
    # 建表语句
    sql='''
        create table student(
        sno int(8) primary key auto_increment,
        sname varchar(30) not null,
        sex varchar(5) ,
        age int(2),
        score float(3,1)
        )
    '''
    cursor.execute(sql)
    print("创建成功")
except Exception as e:
    print(e)
    print("创建失败")
finally:
    # 关闭数据库连接
    con.close()
